﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms
{
    public partial class ListBoxDemo : Form
    {
        public ListBoxDemo()
        {
            InitializeComponent();
        }

        private void ListBoxDemo_Load(object sender, EventArgs e)
        {

        }

        private void btnRight_Click(object sender, EventArgs e)
        {
            if(lstLeft.SelectedItems.Count==0)
            {
                return;
            } else
            {
                lstRight.Items.Add(lstLeft.SelectedItem);
                lstBottom.Items.Add(lstLeft.SelectedItem.ToString() + "移动到右侧窗口");
            }
        }

        private void btnRightAll_Click(object sender, EventArgs e)
        {
            foreach(object item in lstLeft.Items)
            {
                lstRight.Items.Add(item);
                lstBottom.Items.Add("左侧内容全部移动至右侧窗口");
                lstLeft.Items.Clear();
            }
        }

        private void btnLeftAll_Click(object sender, EventArgs e)
        {
            foreach (object item in lstRight.Items)
            {
                lstLeft.Items.Add(item);
                lstBottom.Items.Add("右侧内容全部移动至左侧窗口");
                lstRight.Items.Clear();
            }
        }

        private void btnLeft_Click(object sender, EventArgs e)
        {
            if (lstRight.SelectedItems.Count == 0)
            {
                return;
            }
            else
            {
                lstLeft.Items.Add(lstRight.SelectedItem);
                lstBottom.Items.Add(lstRight.SelectedItem.ToString() + "移动到左侧窗口");
                lstRight.Items.Remove(lstRight.SelectedItem);
            }
        }
    }
}
